﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Contracts;
using WcfContrib.Client;

namespace WcfContrib.Showcase.Client
{
    /// <summary>
    /// Build your own client channel manager
    /// </summary>
    class MyServiceClient : ClientChannel<MyServiceClient, IService>
    {
        /// <summary>
        /// Can create delegation methods to make things prettier if you like
        /// </summary>
        public void Do(Foo foo)
        {
            Channel.Do(foo);
        }

        protected override void InitializeRuntime()
        {
            //This would be a proper place to deal with metadata and manage behaviors / extensions
            base.InitializeRuntime();
        }

        protected override InvokeErrorAction OnInvokeException(ChannelExceptionEventArgs args)
        {
            //This would be a proper place to put your own login for invocation exceptions
            //you can control the action that will be done - throw / suppress
            return base.OnInvokeException(args);
        }

        protected override object CreateChannelCore(System.ServiceModel.ChannelFactory factory)
        {
            //you can change anything you like in the creation of the communication channel
            return base.CreateChannelCore(factory);
        }

        protected override System.ServiceModel.ChannelFactory CreateChannelFactoryCore(string endpointName)
        {
            //you can change anything you like in the creation of the channel factory
            //E.g. creating a pre-defined known factory with binding and endpoint address without relying on the configuration
            return base.CreateChannelFactoryCore(endpointName);
        }
    }
}
